package handler

import (
	"context"
	"fmt"
	"github.com/gin-gonic/gin"
	"live-broadcast/api/request"
	"live-broadcast/global"
	"live-broadcast/internal/dao"
	"live-broadcast/internal/model"
	"net/http"
	"time"
)

func AddIlleqal(c *gin.Context) {

}

func ListIlleqal(c *gin.Context) {

}

func GetNumBerIlleqal(c *gin.Context) {
	var req request.GetNumBerIlleqal
	var illeqls []model.Illeqal

	if err := c.ShouldBind(&req); err != nil {
		return
	}

	if req.UserId == 0 {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"msg":  "验证失败",
			"data": nil,
		})
		return
	}

	err := dao.GetWhereFile(&model.Illeqal{UserId: req.UserId}, &illeqls)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"msg":  "查询失败",
			"data": nil,
		})
		return
	}

	if len(illeqls) > 3 {
		global.RDB.Set(context.Background(), "illeqal"+fmt.Sprintf("%d", req.UserId), req.UserId, time.Hour*24)
	}

}
